.data
GdtLimit DW ? ; GDT limit (size-1)
GdtBase DD ? ; GDT base address
.code
sgdt fword ptr GdtLimit
.data
LastSelector DW ? ; Selector for the new code segment.
.code
movzx eax, GdtLimit
xor eax, 7
test eax, 7
jz done
and eax, 0FFF8h
sub eax, 8
done:
mov LastSelector, ax ; store last selector value
add eax, GdtBase
.code
sub ecx, ecx
mov cx, cs
and ecx, 0FFF8h
add ecx, GdtBase ; Now DS:ECX points to code descriptor
mov edx, [ecx]
mov [eax], edx
mov edx, [ecx+4]
mov [eax+4], edx ; copy
and byte ptr [eax+5], 10011111b
.data
IdtLimit DW ?
IdtBase DD ?
OldInt0 DD ?
DD ?
.code
sidt fword ptr IdtLimit
mov eax, IdtBase
; now we'll save original exception 0 handler.
mov ecx, [eax]
mov OldInt0, ecx
mov ecx, [eax+4]
mov OldInt0[4], ecx
; now modify int 0 gate to have it point to our code segment on level 0.
mov cx, LastSelector
mov [eax+2], cx ; Set selector
mov ecx, offset int_0_handler
mov [eax], cx ; Set low word of offset
shr ecx, 16
mov [eax+6], cx ; Set high word of offset
; Now as exception 0 gate is set, enter the gate.
sub eax, eax
div eax
int_0_handler:
; Now restore original exception 0 gate - we don't need it anymore
mov eax, IdtBase
mov ecx, OldInt0
mov [eax], ecx
mov ecx, OldInt0[4]
mov [eax+4], ecx
This page is created using Microsoft(R) Notepad. Visited by 520 souls since creation of the world